<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "asr_files".
 *
 * @property int $files_id 文件的id
 * @property string $name 文件的名字
 * @property string $path 文件的路径
 * @property int $create_time 文件的创建时间
 * @property int $update_time 文件的更新时间
 */
class AsrFiles extends \yii\db\ActiveRecord
{
    public $file;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'asr_files';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['create_time', 'update_time'], 'integer'],
            [['name'], 'string', 'max' => 100],
            [['filepath'], 'string', 'max' => 255],
            [['update_time'], 'default', 'value'=> time()],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'files_id' => 'Files ID',
            'name' => 'Name',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
        ];
    }

    public function upload()
    {
        if ($this->validate()) {
            $this->filepath->saveAs('uploads/' . $this->filepath->baseName . '.' . $this->imageFile->extension);
            return true;
        } else {
            return false;
        }
    }

}
